<html>
<head>

  <title>代理在线充值</title>
    <meta charset="utf-8"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="keywords"/>
    <meta name="description"/>
    <link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.0.3/jquery.js"></script>
</head>
<body>
   <style>
     ul{padding: 0;margin: 0;}
     ul li img{text-align: center;}
     ul li{list-style-type:none;text-align: center;padding-top:0.2em;}
     *{font-family:黑体, Arial, Helvetica, sans-serif;font-size:15px;color: #1d1007; line-height:24px};
   </style>
   <div class="container">
      <div class="col-xs-12">
           <div class="col-xs-12">
               <h2>这是测试网页换成你自己的注意下面的JS，还有 jquery不能少</h2>
               <div class="form-group" style="margin-top:3em;">
                   <input type="text" class="form-control" id="firsttel" placeholder="请输入手机号">
               </div>
               <div class="form-group" style="margin-top:1.5em;">
                   <input type="text" class="form-control" id="number" placeholder="请输入数量">
               </div>
               <p style="text-align:center;">100以上单价1.5元。500以上单价1.2元。1000以上单价1元</p>
           </div>
           <div class="col-xs-12"></div>
	    </div>
   </div>
   <div class="row" style="margin-top:2.6em;">
       <button id="weixinkq" type="button" class="btn btn-primary btn-lg btn-block" style="background:#00C800;border:none;">立即充值</button>
   </div>
   <script>
       var msg_id; //定义全局变量
       $("#weixinkq").click(function(){

                var number=1;       //充值数量-模拟向后端发送数据
                var firsttel=1;    //用户充值的ID编号 -  模拟向后端发送数据
                $.post('http://m.eyqq.com/index/pays/index',      //向后端发送数据 (注意换成Pays控制器下面的，index方法，去请求数据)
                {
                    number:number,
                    firsttel:firsttel
                },
                function (data){
                     var objdata = JSON.parse(data);
					 msg_id=objdata['msg'];  //注意msg_id 需要是 全局变量
                     if(objdata['error']==0){
                       alert(objdata['msg']);
                     }else{
                       var jsonok=objdata['parameters'];  //返回数据结果
                       callpay(jsonok);
                     }
                });
       });
    function jsApiCall(v)
    {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
             {
                "appId":v.appId,
                "nonceStr":v.nonceStr,
                "package":v.package,
                "paySign":v.paySign,
                "signType":v.signType,
                "timeStamp":v.timeStamp
             },
            function(res){
                if(res.err_msg == 'get_brand_wcpay_request:ok'){
                    alert('恭喜您，支付成功!更新可能会有5～10秒延迟!');
					window.location.href="#"; 
                }else{
                    alert(JSON.stringify(res));
                }
            }
        );
    }

    function callpay(v)
    {

        if (typeof WeixinJSBridge == "undefined"){

            if( document.addEventListener ){

                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);

            }else if (document.attachEvent){
              
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall(v);
        }
    }

</script>
</div>
</body>
</html>